##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
	listen 80 default_server;
	listen [::]:80 default_server;

	# SSL configuration
	#
	# listen 443 ssl default_server;
	# listen [::]:443 ssl default_server;
	#
	# Note: You should disable gzip for SSL traffic.
	# See: https://bugs.debian.org/773332
	#
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See: https://bugs.debian.org/765782
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;

	#root /var/www/html;
	root /var/www/pelican;

	# Add index.php to the list if you are using PHP
	index index.php index.html index.htm index.nginx-debian.html idlerpg.html;

	server_name demur.red;

#	location / {
#		# First attempt to serve request as file, then
#		# as directory, then fall back to displaying a 404.
#		try_files $uri $uri/ =404;
#	}

## Stop logging /theme
location /theme {
  access_log off;
  }

	### IRPG ### {{{
	location /irpg {
		alias /var/www/irpg;
		#try_files $uri $uri/ idlerpg.html =404;

		#location ~ \.php$ {
		location ~ ^(.+\.php)(.*)$ {
				fastcgi_split_path_info       ^(.+\.php)(.*)$;
				try_files $uri =404;
				fastcgi_pass unix:/var/run/php5-fpm.sock;
				fastcgi_index index.php;
				## https://stackoverflow.com/questions/28490391/how-to-properly-configure-alias-directive-in-nginx
				fastcgi_param SCRIPT_FILENAME $request_filename;
				include fastcgi_params;
		}

		location /irpg/(php|js|css) {
			access_log off;
		}
	}
	### End IRPG ### }}}

	### TTRSS ### {{{
	location /ttrss {
		alias /var/www/tt-rss;
		access_log /var/log/nginx/ttrss_access.log;
		error_log /var/log/nginx/ttrss_error.log info;
		#try_files $uri $uri/ idlerpg.html =404;

		#location ~ \.php$ {
		location ~ ^(.+\.php)(.*)$ {
				fastcgi_split_path_info       ^(.+\.php)(.*)$;
				try_files $uri =404;
				fastcgi_pass unix:/var/run/php5-fpm.sock;
				fastcgi_index index.php;
				## https://stackoverflow.com/questions/28490391/how-to-properly-configure-alias-directive-in-nginx
				fastcgi_param SCRIPT_FILENAME $request_filename;
				include fastcgi_params;
		}

		#location /ttrss/(php|js|css) {
			#access_log off;
		#}
	}
	### End IRPG ### }}}

	### YOURLS ### {{{
	location /s {
		alias /var/www/YOURLS;
		access_log /var/log/nginx/yourls_access.log;
		error_log /var/log/nginx/yourls_error.log info;

		# Try files, then folders, then yourls-loader.php
		# --- The most important line ---
		try_files $uri $uri/ /yourls-loader.php;
		#try_files $uri $uri/ /yourls-loader.php?$args;
		#index yourls-loader.php;

		#if (!-e $request_filename){
			#rewrite ^/s/(.*)$ /s/yourls-loader.php break;
		#}

		# PHP engine
		location ~ \.php$ {
			try_files      $uri =404;
			#try_files $uri /yourls-loader.php;
			fastcgi_pass   unix:/var/run/php5-fpm.sock;
			fastcgi_index  index.php;
			## https://stackoverflow.com/questions/28490391/how-to-properly-configure-alias-directive-in-nginx
			fastcgi_param SCRIPT_FILENAME $request_filename;
			fastcgi_split_path_info ^(.+\.php)(/.+)$;
			include        fastcgi_params;
		}
	}
	### End YOURLS ### }}}

	#### piwik ### {{{
	#location /piwik {
		#alias /var/www/piwik;
	#}

	#location ~ /piwik/.+\.php$ {
		#try_files $uri =404;
		#fastcgi_pass unix:/var/run/php5-fpm.sock;
		### https://stackoverflow.com/questions/28490391/how-to-properly-configure-alias-directive-in-nginx
		#fastcgi_param SCRIPT_FILENAME $request_filename;
		#include fastcgi_params;
	#}
	#### End piwik ### }}}

	### GateOne redirect to HTTPS ### {{{
	#location / {
	#}
	location /go {
	    rewrite ^ https://$http_host$request_uri? permanent;
	}
	### End GateOne ### }}}

	### php attempt ### {{{
		# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
	location ~ \.php$ {
			try_files $uri =404;
			fastcgi_pass unix:/var/run/php5-fpm.sock;
			fastcgi_index index.php;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
			include fastcgi_params;
	}
	### end php ### }}}

	### Error Redirects ### {{{
	# Redirect server error pages
	error_page 500 502 503 504 /pages/50x;
	error_page 404 /pages/404;
	error_page 403 /pages/403;
	### End Error ### }}}

	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	#location ~ /\.ht {
	#	deny all;
	#}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#	listen 80;
#	listen [::]:80;
#
#	server_name example.com;
#
#	root /var/www/example.com;
#	index index.html;
#
#	location / {
#		try_files $uri $uri/ =404;
#	}
#}
